package com.it.sun.easychat.model.util;

import com.it.sun.easychat.model.constant.HttpResponseCode;
import com.it.sun.easychat.model.constant.HttpResponseMsg;
import com.it.sun.easychat.model.vo.ResultVO;

/**
 * @author sunmannian
 * @ClassName ResultHelper
 * @Date 2020/5/24 9:59
 * @Version V1.0
 * Description  <返回消息体对象工具类>
 * Copyright (C) 北京中电兴发科技有限公司  since 2020/5/24
 */
public class ResultHelper {

    public static <T> ResultVO getSuccess(T data) {
        return getSuccess(HttpResponseCode.SUCCESS_CODE,
                HttpResponseMsg.SUCCESS_MSG,
                data);
    }

    public static <T> ResultVO getSuccess(String msg, T data) {
        return getSuccess(HttpResponseCode.SUCCESS_CODE,
                msg,
                data);
    }

    /**
     * <描述方法功能>
     * <返回成功消息对象>
     *
     * @param code
     * @param msg
     * @param data
     * @return ResultVO
     * @Author sunmannian
     * @Description
     * @Date 2020/5/24 10:12
     **/
    public static <T> ResultVO getSuccess(int code, String msg, T data) {
        ResultVO<T> r = getResultVO(code, msg, data);
        return r;
    }


    public static <T> ResultVO getFailed(T data) {
        return getFailed(HttpResponseCode.FAILED_CODE,
                HttpResponseMsg.FAILED_MSG,
                data);
    }

    public static <T> ResultVO getFailed(String msg, T data) {
        return getFailed(HttpResponseCode.FAILED_CODE,
                msg,
                data);
    }

    /**
     * <描述方法功能>
     * <获取失败消息对象>
     *
     * @param code
     * @param msg
     * @param data
     * @return ResultVO
     * @Author sunmannian
     * @Description
     * @Date 2020/5/24 10:14
     **/
    public static <T> ResultVO getFailed(int code, String msg, T data) {
        ResultVO<T> r = getResultVO(code, msg, data);
        return r;
    }

    public static ResultVO<Void> success() {
        return getSuccess(null);
    }

    public static ResultVO<Void> failed() {
        return getFailed(null);
    }

    private static <T> ResultVO<T> getResultVO(int code, String msg, T data) {
        ResultVO<T> r = new ResultVO<>();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
}
